import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Req,
  Query,
} from '@nestjs/common';
import { UserService } from './user.service';
import { CreateUserDto } from './dto/create-user.dto';
import { UpdateUserDto } from './dto/update-user.dto';
import { Public } from '../auth/decorator/public';

@Controller('user')
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Post('create')
  create(@Body() createUserDto: CreateUserDto) {
    return this.userService.create(createUserDto);
  }
  @Post('add')
  addUser(@Body() body) {
    return this.userService.addUser(body);
  }
  @Get('all')
  findAll(@Query() query) {
    return this.userService.findAll(query);
  }

  @Get('friend/:code')
  findFriend(@Param('code') code: string) {
    return this.userService.findFriend(code);
  }

  // 获取登陆用户信息
  @Get('info')
  getUserByToken(@Req() request) {
    return this.userService.findOne(null, request.userInfo.username);
  }

  @Get('/detail/:id')
  findOne(@Param('id') id: string) {
    return this.userService.findOne(+id);
  }

  @Patch('update/')
  update(@Body() body) {
    return this.userService.update(body);
  }

  @Delete('/del/:id')
  remove(@Param('id') id: string) {
    return this.userService.remove(id);
  }
}
